{__NOLAYOUT__}
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/agent/manage/css/found.css"/>
    <script type="text/javascript" src="/agent/manage/js/jquery.1.9.1.js" ></script>
    <script type="text/javascript" src="/agent/manage/js/layer.js" ></script>
    <link rel="stylesheet" type="text/css" href="/agent/manage/css/layer.css"/>
    <script type="text/javascript" src="/agent/manage/js/rem.js" ></script>
    <title>创建工单</title>
</head>
<body>
<form id="form2" action="add" enctype="multipart/form-data"  method="post">
    <ul class="order_money">
        <li>
            <p class="titie">基本信息</p>
            <input class="order_num" type="text" name="order_sn" value="" placeholder="请输入订单编号" />
        </li>
        <li>
            <textarea name="content" value="" placeholder="请简述您的问题" ></textarea>
        </li>
    </ul>
    <div class="pingzheng">
        <p class="titie">添加图片</p>
        <div class="z_photo">
            <div class="z_file" data-id="1" onclick="fileSelect($(this));">
                <span>+</span>
                <em class="number">0/5</em>
            </div>
            <input type="file" hidden="hidden" name="file[]" id="file_1" onchange="uploadFile();" value="" accept="image/*" multiple  />
            <input type="file" hidden="hidden" name="file[]" id="file_2" onchange="uploadFile();" value="" accept="image/*" multiple  />
            <input type="file" hidden="hidden" name="file[]" id="file_3" onchange="uploadFile();" value="" accept="image/*" multiple  />
            <input type="file" hidden="hidden" name="file[]" id="file_4" onchange="uploadFile();" value="" accept="image/*" multiple  />
            <input type="file" hidden="hidden" name="file[]" id="file_5" onchange="uploadFile();" value="" accept="image/*" multiple  />
            <input type="hidden" name="img[]" id="file_base_1" value=""    />
            <input type="hidden" name="img[]" id="file_base_2" value=""    />
            <input type="hidden" name="img[]" id="file_base_3" value=""    />
            <input type="hidden" name="img[]" id="file_base_4" value=""    />
            <input type="hidden" name="img[]" id="file_base_5" value=""    />
        </div>
    </div>
    <input class="pay" type="submit" name="" id="" value="立即提交" />
</form>
<script>

  $('.order_num').on('change',function () {
    $.ajax({ url:'orderSn',
      data:{order_sn:this.value},
      success:function (res) {
        if(res.status == 0)
        {
          layer.open({
            content:res.msg ,
            skin: 'msg',
            time: 2 //2秒后自动关闭
          });
          $('.order_num').val('');
          return false
        }else{
          layer.open({
            content:res.msg ,
            skin: 'msg',
            time: 2 //2秒后自动关闭
          });
          return false
        }
      }
    });
  });
  $('#form2').submit(function () {
    var order_num = $('.order_num').val();
    if(order_num == ""||order_num == null){
      layer.open({
        content:'请填写订单编号' ,
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false
    }
    return true;
  });

  var number = $('.z_file').attr('data-id');
  function fileSelect() {
    document.getElementById('file_'+number).click();
  }
  function uploadFile()
  {
    var file = document.getElementById("file_"+number).files[0];
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function(e){
      $.ajax({
        type:'post',
        url:'/index/agent/upload',
        data:{file:this.result},
        success:function (data) {
          console.log(data);
          if(data.code == 1){
            $("#file_base_"+number).val(data.data);
            layer.open({
              content: '上传成功',
              skin: 'msg',
              time: 2 //2秒后自动关闭
            });
            var html = '<div class="headerBox">\n' +
              '            <img class="img_close" onclick="del($(this))" src="/agent/img/img_close.png"/>' +
              '            <img id="imgBox_'+number+'" src="'+data.data+'"/>\n' +
              '        </div>\n';
            $(".z_photo").prepend(html);
            $('.number').text(number +'/5');
            number++;
            $('.z_file').attr('data-id',number);
            if(number == 6)
            {
              $('.z_file').hide();
            }
            return true;
          }else{
            layer.open({
              content: data.msg,
              skin: 'msg',
              time: 2 //2秒后自动关闭
            });
            return false;
          }
        }
      });

    }
  }
  function del(thi) {
    thi.parent().remove();
    number--;
    $('.number').text(number - 1 +'/5');
    if(number != 6 ){
      $('.z_file').show();
    }
    $('.z_file').attr('data-id',number);
    $('#file_'+number).val('');
  }
</script>

</body>
</html>
